<!--职业资格-->
<blockquote class="layui-elem-quote" style="font-size: 14px">执业资格等级提升积分规则
</blockquote>

<hr class="layui-bg-gray">

<form class="layui-form" action="" id="practice_form">

    <table class="layui-table">
        <colgroup>

            <col width="200">
            <col width="200">
            <col width="200">
            <col width="5%">
        </colgroup>
        <thead>
        <tr>
            <th>执业资格等级</th>
            <th>编码</th>
            <th>积分</th>
            <th>
                <button type="button" class="btn btn-primary" onclick="addPracticeRow()" ><i class="fa fa-plus-circle"></i></button>
            </th>
        </tr>
        </thead>
        <tbody id="practice_body">
        @for(practice in practiceRules){
        <tr>
            <td><input type="text" name="practiceRules[${practiceLP.index}].grade" value="${practice.grade}"  class="layui-input" lay-verify="required"></td>
            <td><input type="text" name="practiceRules[${practiceLP.index}].gradeCode" value="${practice.gradeCode}"  class="layui-input" lay-verify="required"></td>
            <td><input type="text" name="practiceRules[${practiceLP.index}].integral" value="${practice.integral}" class="layui-input" lay-verify="required|number"></td>
            <td>
                <button type="button" class="btn btn-primary " onclick="deletePracticeRow($(this))">
                    <i class="fa fa-trash-o"></i>
                </button>
            </td>
        </tr>
        @}
        </tbody>
    </table>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-top: 20px;">

            <button class="layui-btn" lay-submit lay-filter="practice_form">提交保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>



<template>
    <tr>
        <td><input type="text" name="practiceRules[].grade" autocomplete="off" class="layui-input" lay-verify="required"></td>
        <td><input type="text" name="practiceRules[].gradeCode" autocomplete="off" class="layui-input" lay-verify="required"></td>
        <td><input type="text" name="practiceRules[].integral" autocomplete="off" class="layui-input" lay-verify="required|number"></td>
        <td>
            <button type="button" class="btn btn-primary " onclick="deletePracticeRow($(this))">
                <i class="fa fa-trash-o"></i>
            </button>
        </td>
    </tr>
</template>

<script>
    $(function(){
        initPractice();
    });
    /**
     * 添加行
     */
    function addPracticeRow() {
        var trSize = $("#practice_body>tr").length + 1;
        $("tbody").append($("template").html().replace(/\[]/g,"["+trSize+"]"));
    }

    /**
     * 删除行
     */
    function deletePracticeRow($this) {
        $this.closest("tr").empty();
    }

    /**
     * 提交
     */
    function initPractice() {
        layui.use(['form'], function(){
            var form = layui.form;

            form.on('submit(practice_form)', function(data){
                form.verify();
                $.ajax({
                    type: "POST",
                    url: 'integral/practice_train_add',
                    data: data.field,
                    dataType: "json",
                    success: function(data){
                        Feng.success("保存成功!");
                    }
                });
                return false;
            });
        });
    }

</script>